package com.fduss.artStore.servlet;

import com.fduss.artStore.service.OrderService;
import com.fduss.artStore.service.impl.OrderServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "PayServlet", value = "/pay")
public class PayServlet extends HttpServlet {
    private void doRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String[] orders = request.getParameterValues("orders");
        if (orders == null)
            return;
        OrderService orderService = new OrderServiceImpl();
        for (String order :
                orders) {
            orderService.completeOrder(Integer.parseInt(order));
        }
        response.sendRedirect("./profile.jsp#Records");
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doRequest(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doRequest(request, response);
    }
}
